package cn.com.dhcc.turbo.web.controller.stat;

 
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dhcc.app.core.base.BaseController;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu;
import cn.com.dhcc.app.pub.core.annotation.TurboMenu.LEAF_MENU;
import cn.com.dhcc.turbo.entity.registry.AdapterInfo;
import cn.com.dhcc.turbo.entity.stat.ExchStatStatic;
import cn.com.dhcc.turbo.service.registry.AdapterInfoService;
import cn.com.dhcc.turbo.service.stat.ExchStatStaticService;

@Controller
@RequestMapping("/stat")
@TurboMenu(belongToMenu = LEAF_MENU.EXCH_STATIC)
public class ExchStatStaticController extends BaseController {
	@SuppressWarnings("deprecation")
	private static Logger logger = Log.getExistLogger(LOGTYPE.TURBO);

	@Autowired
	ExchStatStaticService service;
	@Autowired
	AdapterInfoService adapterService;
	/**
	 * 
	 * @param model 
	 * @return
	 */
	
	@RequestMapping(value = "/exch_total_static")
	public String exchTotalStatic(Model model) {
		try {  
			List<AdapterInfo> adapterList = adapterService.getLocalAdapterList();
			List<AdapterInfo> relAdapterList = adapterService.getRelNodeAdapterList();
			List<ExchStatStatic> domInfos=service.getDomInfos(); 
			model.addAttribute("adapterList", adapterList);
		   model.addAttribute("relAdapterList", relAdapterList);
		   model.addAttribute("domList", domInfos);
			
		} catch (Exception e) {
			logger.error("操作失败", e);
		 
		} 
		 
		return "stat/exch_total_static";
	}
	
	
	 /**本节点接收和发送次数
	 *  @param timeType
	  * @param mtime
	 * @param stat_level 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/st_lo_num")
	public Map<String, Object> StLoNum(String timeType,String nt,String stat_level,String own_id,Model model) {
		String msg = "";
		try {
			msg = service.getStLoNum(timeType, nt, stat_level, own_id);
			return jsonSuccessDataResult("success", msg);
		} catch (ServiceException e) {
			msg = "统计失败";
			logger.error(msg, e);
			return jsonFailResult(msg);
		}
	}
 
		
		/**内外网交换频率
		 *  @param timeType
		  * @param mtime
		 * @param stat_level 
		 * @return
		 */
		@ResponseBody
		@RequestMapping(value = "/st_lo_num_net")
		public Map<String, Object> getStLoNumNet(String timeType,String stat_level,String nt,String own_id,Model model) {
			String msg = "";
			try {
				msg = service.getStLoNumNet(timeType, stat_level, nt,  own_id);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
 
		
		  /**内外网交换成功率（月/年）
	   	 *  @param timeType
	   	  * @param mtime
	   	 * @param stat_level 
	   	 * @param own_id   
	   	 */
		@ResponseBody
		@RequestMapping(value = "/st_lo_net_rate")
		public Map<String, Object> getStLoNetRate(Model model,String timeType,String nt,String stat_level,String own_id) {
			String msg = "";
			try {
				msg = service.getStLoNetRate(timeType, nt, stat_level, own_id);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
//		@RequestMapping(value = "/getStLoNetRateSysName_get")
//		public String getStLoNetRateSysName(Model model) {  
//			try {
//				List<ExchStatStatic> sysInfos=service.getSysInfos(); 
//				model.addAttribute(DATA_KEY, sysInfos);
//				return "stat/exch_total_static_stlonetrate_get_sys";
//			} catch (Exception e) {
//				logger.error("操作失败", e);
//				return toAlertPage(model, e.getMessage());
//			}
//		}
//		@RequestMapping(value = "/getStLoNetRateDomName_get")
//		public String getStLoNetRateDomName(Model model) {  
//			try {
//				List<ExchStatStatic> sysInfos=service.getDomInfos(); 
//				model.addAttribute(DATA_KEY, sysInfos);
//				return "stat/exch_total_static_stlonetrate_get_dom";
//			} catch (Exception e) {
//				logger.error("操作失败", e);
//				return toAlertPage(model, e.getMessage());
//			}
//		}
		
		/**
		 * 与本节点交换频率最高的节点（月/年）
		 * @param NT 统计时间 
		 * @param timeType      
		 * @return   
		 * @throws DaoException
		 */ 
		@ResponseBody
		@RequestMapping(value = "/st_lo_rel_node_rate")
		public Map<String, Object> getStLoRelNodeRate(String timeType,String nt,Model model) {
			String msg = "";
			try {
				msg = service.getStLoRelNodeRate(timeType, nt);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
		
		
		/**
		 * 与本节点交换频率最高的适配器（月/年）
		 * @param NT 统计时间 
		 * @param timeType      
		 * @return   
		 * @throws DaoException
		 */ 
		@ResponseBody
		@RequestMapping(value = "/st_lo_rel_adapter_rate")
		public Map<String, Object> getStLoRelSysRate(String timeType,String nt,Model model) {
			String msg = "";
			try {
				msg = service.getStLoRelSysRate(timeType, nt);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
		
		/**本节点发送（按适配器)
	  	 *  @param timeType
	  	  * @param nt 
	  	 * @return
	  	 * @throws DaoException
	  	 */
	  	@ResponseBody
		@RequestMapping(value = "/st_lo_num_sys_send")
		public Map<String, Object> getStLoNumSysSend(String timeType,String nt,Model model) {
			String msg = "";
			try {
				msg = service.getStLoNumSysSend(timeType, nt);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
	  	
	  	/**本节点接收（按适配器)
	  	 *  @param timeType
	  	  * @param nt 
	  	 * @return
	  	 * @throws DaoException
	  	 */
	  	@ResponseBody
		@RequestMapping(value = "/st_lo_num_sys_rev")
		public Map<String, Object> getStLoNumSysRev(String timeType,String nt,Model model) {
			String msg = "";
			try {
				msg = service.getStLoNumSysRev(timeType, nt);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
	  	
	  	/**本节点发送（按数据分类)
	  	 *  @param timeType
	  	  * @param nt 
	  	  * @param stat_level
	  	  * @param  own_id
	  	  * EXCH_TYPE =1 发送
	  	 * @return 
	  	 * @throws DaoException
	  	 */
	  	@ResponseBody
		@RequestMapping(value = "/st_lo_num_dtype_send")
		public Map<String, Object> getStLoNumDtypeSend(String timeType,String nt,String stat_level,String own_id,Model model) {
			String msg = "";
			try {
				msg = service.getStLoNumDtypeSend(timeType, nt, stat_level, own_id);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
	  	
 
	  	
	  	/**本节点接收（按数据分类)
	  	 *  @param timeType
	  	  * @param nt 
	  	  * @param stat_level
	  	  * @param  own_id
	  	  * EXCH_TYPE =2 接收
	  	 * @return 
	  	 * @throws DaoException
	  	 */
	  	@ResponseBody
		@RequestMapping(value = "/st_lo_num_dtype_rev")
		public Map<String, Object> getStLoNumDtypeRev(String timeType,String nt,String stat_level,String own_id,Model model) {
			String msg = "";
			try {
				msg = service.getStLoNumDtypeRev(timeType, nt, stat_level, own_id);
				return jsonSuccessDataResult("success", msg);
			} catch (ServiceException e) {
				msg = "统计失败";
				logger.error(msg, e);
				return jsonFailResult(msg);
			}
		}
 
	 
}
